import ImgBox from '../../components/Common/ImgBox'
import BadgeLeft from '../../components/Monitor/BadgeLeft.vue'
import * as echarts from 'echarts'
import { baseURL } from "../../utils/ipConfig";
export default {
    name: 'Monitor',
    components: {
        ImgBox,
        BadgeLeft,
    },
    data() {
        return {
            activeName: 'first',
            height: "46vh",
            box: [
                {
                    url: require('../../assets/image/BSC.png'),
                    name: 'BSC（万）',
                    data: 0
                },
                {
                    url: require('../../assets/image/RNC.png'),
                    name: 'RNC（万）',
                    data: 0
                },
                {
                    url: require('../../assets/image/EnodeB.png'),
                    name: 'EnodeB（万）',
                    data: 0
                },
                {
                    url: require('../../assets/image/NB-IOY.png'),
                    name: 'NB-IOY（万）',
                    data: 0
                },

            ],
            form: {
                name: '103',
                region: '',
                resource: '企业apn',
            },
            total: 0,
            currentPage4: 1,
            pageNum: 1,
            pageSize: 15,
            areaCode: "0850",
            tableData: [],
            search: "",
            bei: [],
            placeholderval: "请输入企业apn关键字",
        };
    },
    watch: {
        'form.resource'(newValue) {
            if (newValue == "企业apn") {
                this.placeholderval = "请输入企业apn关键字";
            } else {
                this.placeholderval = "请输入用户号码关键字";
            }
        },
        search() {
            this.query();
        }
    },
    beforeMount() {

        if (document.documentElement.clientWidth <= 1600) {
            this.height = "36vh";
        } else {
            this.height = "46vh"
        }
    },
    mounted() {
        this.getCustomMonitoringData();
    },
    methods: {
        getCustomMonitoringData() {
            let _this = this;
            let param = new URLSearchParams();
            param.append("pageNum", _this.pageNum);
            param.append("pageSize", _this.pageSize);
            param.append("apptype_code", _this.form.name);
            _this.$ajax
                .post(`${baseURL.ip1}/pc/getCustomMonitoringData`, param)
                .then(function (res) {
                    //请求成功
                    let resData = res.data;
                    if (resData.code == 200 || resData.code == 0) {
                        _this.tableData = resData.data;
                        if (_this.total !== resData.count) {
                            _this.total = resData.count;
                        }
                    }
                })
                .catch(function (error) {
                    //请求失败
                    console.log(error);
                });
        },
        // 查询
        query() {
            let _this = this;
            if (_this.form.resource == "企业apn") {
                let param = new URLSearchParams();
                param.append("apn", _this.search);
                param.append("msisdn", "");
                param.append("pageNum", _this.pageNum);
                param.append("pageSize", _this.pageSize);
                _this.$ajax
                    .post(`${baseURL.ip1}/pc/getCustomMonitoringData`, param)
                    .then(function (res) {
                        //请求成功
                        let resData = res.data;
                        if (resData.code == 200 || resData.code == 0) {
                            _this.tableData = resData.data;
                            if (_this.total !== resData.count) {
                                _this.total = resData.count;
                            }
                        }
                    })
                    .catch(function (error) {
                        //请求失败
                        console.log(error);
                    });
            } else {
                let param = new URLSearchParams();
                param.append("apn", "");
                param.append("msisdn", _this.search);
                param.append("pageNum", _this.pageNum);
                param.append("pageSize", _this.pageSize);
                _this.$ajax
                    .post(`${baseURL.ip1}/pc/getCustomMonitoringData`, param)
                    .then(function (res) {
                        //请求成功
                        let resData = res.data;
                        if (resData.code == 200 || resData.code == 0) {
                            _this.tableData = resData.data;
                            if (_this.total !== resData.count) {
                                _this.total = resData.count;
                            }
                        }
                    })
                    .catch(function (error) {
                        //请求失败
                        console.log(error);
                    });
            }

        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.pageNum = 1;
            this.getCustomMonitoringData();
        },
        handleCurrentChange(val) {
            this.pageNum = val;
            this.getCustomMonitoringData();
        },
        filterOne(dataList, value, type) {
            var s = dataList.filter(function (item, index, arr) {
                for (let j = 0; j < type.length; j++) {
                    if (item[type[j]] != undefined || item[type[j]] != null) {
                        if (item[type[j]].indexOf(value) >= 0) {
                            return item;
                        }
                    }
                }
            });
            return s;
        },
        Reset() {
            this.form = {
                name: '',
                region: '',
                resource: '',
            };
            this.search = "";
        },
    },
}